package structure;

import java.util.Random;
import java.util.Scanner;

public class branch06 {
    public static void main(String[] args) {
        //创建一个Random对象
        Random r = new Random();
        for (int i = 1; i <=9; i++) {
            //调用Random功能，nextInt得到随机数
            int date = r.nextInt(10);  //0-9
            System.out.println(date);
        }

        for (int i = 1; i <=4 ; i++) {
            for (int j = 1; j <= 5; j++) {
                int date2 = r.nextInt(15) + 3;  //3-17
                System.out.print(date2 + " ");
            }
            System.out.println();
        }


//        在1-100中猜测一个数字，与生成的随机数进行比较大小
        int date3 = r.nextInt(100) + 1;  //生成1-100数字
        Scanner sc = new Scanner(System.in);    //导入键盘扫描器
        while (true){                           //死循环
        System.out.println("请您输入数字：");      //扫描键盘
        int num = sc.nextInt();

        if(num > date3){                         // if分支结构
            System.out.println("您输入的数字过大");
        } else if (num < date3) {
            System.out.println("您输入的数字过小");
        }else{
                System.out.println("恭喜您猜对了");
            break;
        }
        }
    }
}
